package com.wtwd.campus.receiver;

import com.wtwd.campus.annotation.MsgType;
import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.*;
import com.wtwd.campus.service.CustomerDealCmdService;
import com.wtwd.campus.service.DeviceInfoService;
import com.wtwd.campus.service.IRMFeignClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author mjy(该协议暂时只针对于vcom 后面可能扩充裕其他客户 需要针对客户进行不同的业务处理 主要是存于数据库的表不一致 ， 故暂只做vcom的)
 * @date 2022/11/01
 * @description
 */
@Service
@MsgType(value = Constants.GET_PHONE)
public class GetPhoneHandler implements IReceiverHandler {

    @Resource
    private IRMFeignClientService irmFeignClientService;

    @Resource
    private DeviceInfoService deviceInfoService;

    @Autowired
    @Qualifier("CustomerDealCmdServiceImpl")
    private CustomerDealCmdService customerDealCmdService;


    @Override
    public void handlerMessage(MqMessage mqMessage) {
        MqGeneralValueResult mqGeneralValueResult = (MqGeneralValueResult) mqMessage.getObject();
        String imei = mqGeneralValueResult.getImei();
        String commandNumber = mqGeneralValueResult.getCommandNumber();
        String type = mqGeneralValueResult.getValue();
        DeviceInfo deviceInfo = deviceInfoService.getDeviceByImei(imei);
        MqPhoneDatas phoneDatas = null;
        if (deviceInfo != null) {
            if (deviceInfo.getCustomerId() != null && deviceInfo.getDeviceType() != null) {//暂时只针对vcom设备进行处理
                phoneDatas=customerDealCmdService.getPhoneData(deviceInfo.getImei(), deviceInfo.getDeviceType(), deviceInfo.getCustomerId(), type,commandNumber);
                if (phoneDatas!=null){
                    irmFeignClientService.replyGetPhone(phoneDatas);
                    customerDealCmdService.dealCustomerGetPhoneData(deviceInfo.getImei(), deviceInfo.getDeviceType(), deviceInfo.getCustomerId(), type, phoneDatas);
                }
            } else {//平台的暂不处理

            }
        }

    }
}
